package MULE.Model.Logic;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import MULE.Model.*;
import MULE.Model.Panel.*;

/**
 * Logic module responsible for processing the Town panel and its inputs.
 * 
 * @author jstep
 */
public class TownLogic extends MulePresenter implements ActionListener {

	/**
	 * An enumeration of this presenter's supported action commands.
	 */
	public enum ActionCommand {
		ENTER_STORE, ENTER_ASSAY_OFFICE, EXIT_TOWN;
	}

	/**
	 * Creates a new logic module responsible for manipulating the town panel
	 * and processing the town panel's inputs.
	 * 
	 * @param view
	 *            The town panel.
	 */
	public TownLogic(TownPanel view) {
		super(view);
		view.addExitListener(this);
		// Get main content area dimensions.
		Dimension panelSize = MuleDriver.getGameViewSize();
		// Create Store.
		StorePanel storePanel = new StorePanel(panelSize);
		StoreLogic storeLogic = new StoreLogic(storePanel);
		view.addStoreEntranceListener(storeLogic);
		// Create Land Office.
		MapPanel mapPanel = (MapPanel) MuleDriver.getMapLogic().getView();
		LandOfficePanel landOfficePanel = new LandOfficePanel(panelSize,
				mapPanel);
		LandOffice landOffice = new LandOffice(landOfficePanel);
		view.addLandOfficeEntranceListener((ActionListener) landOffice);
		// Create Pub.
		PubPanel pubPanel = new PubPanel(panelSize);
		PubLogic pub = new PubLogic(pubPanel);
		view.addPubEntranceListener(pub);
		// TODO Create Store.
	}

	/**
	 * Event handler. Responds to input from the Town panel.
	 * 
	 * @param e
	 *            The event which was fired from the town panel.
	 */
	public void actionPerformed(ActionEvent e) {
		// Exit button is pressed.
		if (e.getActionCommand().equals(ActionCommand.EXIT_TOWN.toString())) {
			MapPanel mapPanel = (MapPanel) MuleDriver.getMapLogic().getView();
			MuleDriver.setGameView(mapPanel);
		}
	}

}